package com.tools.pgsql;

import java.sql.*;

public class PostgreSQLTest {
    public static void main(String[] args){

//         连接参数
        String url = WXPgSqlAccount.lf_url; // 替换为您的数据库 URL
        String user = WXPgSqlAccount.lf_acc; // 替换为您的数据库用户名
        String password = WXPgSqlAccount.lf_psw; // 替换为您的数据库密码

        try {
            // 建立数据库连接
            Connection conn = DriverManager.getConnection(url, user, password);
            // 创建 Statement 对象来执行 SQL 语句
            Statement stmt = conn.createStatement();
            // 执行查询并获取结果集
            ResultSet rs = stmt.executeQuery("SELECT version()");
            DatabaseMetaData metaData = conn.getMetaData();
            ResultSet tables = metaData.getTables(null, null, "%", null);

            String tableName = "app_ectrip_wushan_ticket_analysis_dtype";
            String schemaPattern = "wslfjt";

            ResultSet set = metaData.getTables(null, schemaPattern, tableName, null);

            ResultSet columns = metaData.getColumns(null, schemaPattern, tableName, null);
            
//            while (tables.next()) {
//                String tempName = tables.getString("TABLE_NAME");
//                System.out.println("Table Name: " + tempName);
//            }

//            while (set.next()) {
//                String tempName = tables.getString("TABLE_NAME");
//                System.out.println("set Table Name: " + tempName);
//            }
            while (columns.next()) {
                String columnName = columns.getString("COLUMN_NAME");
                String columnType = columns.getString("DATA_TYPE");
                int columnSize = columns.getInt("COLUMN_SIZE");
                System.out.println("Column Name: " + columnName + ", Data Type: " + columnType + ", Size: " + columnSize);
            }

            // 关闭连接
            rs.close();
            stmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
